﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Dycox.Reporting
{
    [TypeConverter(typeof(BoundsConverter))]
    public struct Bounds
    {
        public Bounds(RectangleF rect)
            : this(rect.Left, rect.Top, rect.Width, rect.Height)
        {
        }

        public Bounds(PointF point, SizeF size)
            : this(point.X, point.Y, size.Width, size.Height)
        {

        }

        public Bounds(float left, float top, float width, float height)
        {
            _left = left;
            _top = top;
            _width = width;
            _height = height;
        }

        private float _left;

        public float Left
        {
            get { return _left; }
            set { _left = value; }
        }

        private float _top;

        public float Top
        {
            get { return _top; }
            set { _top = value; }
        }

        private float? _width;

        public float Width
        {
            get { return _width.GetValueOrDefault(); }
            set { _width = value; }
        }

        private float? _height;

        public float Height
        {
            get { return _height.GetValueOrDefault(); }
            set { _height = value; }
        }

        public PointF Location
        {
            get
            {
                return new PointF(_left, _top);
            }
            set
            {
                _left = value.X;
                _top = value.Y;
            }
        }

        public SizeF Size
        {
            get
            {
                return new SizeF(Width, Height);
            }
            set
            {
                _width = value.Width;
                _height = value.Height;
            }
        }

        public RectangleF ToRectangle()
        {
            return new RectangleF(Left, Top, Width, Height);
        }

        public static implicit operator RectangleF(Bounds bounds)
        {
            return bounds.ToRectangle();
        }

        public static implicit operator Bounds(RectangleF rect)
        {
            return new Bounds(rect);
        }
    }
}
